package com.jzd.fwserver

import com.jzd.fwserver.util.Config
import com.jzd.fwserver.util.toHexString
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.socket.DatagramPacket
import io.netty.handler.codec.MessageToMessageEncoder

class Encoder:MessageToMessageEncoder<ByteArray>()
{
    override fun encode(ctx: ChannelHandlerContext?, data : ByteArray?, out: MutableList<Any>?)
    {
        data?.let {
            val buffer = ctx?.alloc()?.buffer(data.size)
            buffer?.writeBytes(it)
            Config.sender?.let {
                out?.add(DatagramPacket(buffer, Config.sender))
                println("[send]:${data.toHexString()}")
            }
        }
    }
}